﻿using System;
using System.Collections.ObjectModel;
using System.Web;

namespace Medianamik.Core
{
    /// <summary>
    ///   Classe représentant un "Module" dans Médianamik
    /// </summary>
    public class MedianamikModule : SystemNode<MedianamikModule>
    {
        public override string DisplayName
        {
            get { return (string) HttpContext.GetGlobalResourceObject("SiteMap", Alias); }
        }

        public override Guid SystemNodeTypeID
        {
            get { return MedianamikTypes.Module; }
        }

        public string Alias
        {
            get { return DefaultInstance.Properties["Alias"].GetValue<string>(); }
            set { DefaultInstance.Properties["Alias"].SetValue(value); }
        }

        public string Class
        {
            get { return DefaultInstance.Properties["Class"].GetValue<string>(); }
            set { DefaultInstance.Properties["Class"].SetValue(value); }
        }

        public bool ShowInPublishing
        {
            get { return DefaultInstance.Properties["ShowInPublishing"].GetValue<bool>(); }

            set { DefaultInstance.Properties["ShowInPublishing"].SetValue(value); }
        }

        private Collection<MedianamikPage> _pages;
        public Collection<MedianamikPage> Pages
        {
            get
            {
                return _pages ?? (_pages = 
                    NodeManager.GetNodes<MedianamikPage>(new Param(MedianamikProperties.WebPageModuleId,
                        new[] { ID.ToString() }), MedianamikTypes.Module));
            }
        }

        public Guid? SearchResultPageId
        {
            get { return DefaultInstance.Properties["SearchResultPage"].GetValue<Guid?>(); }
            set { DefaultInstance.Properties["SearchResultPage"].SetValue(value); }
        }
    }
}